package com.zty.xiaomi.server.Vo;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @author Losca
 * @date 2021/9/15 16:32
 */
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ResponseVO<T> {
    private Integer code;
    private String msg;
    private T data;

    /**
     *
     * 只能传入规定的code enum定义
     * @param msg
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResponseVO<T> success(String msg,T data){
        return new ResponseVO<>(ResponseCode.SUCCESS.getCode(), msg,data);
    }

    public static <T> ResponseVO<T> success(String msg){
        return new ResponseVO<>(ResponseCode.SUCCESS.getCode(), msg,null);
    }
    public static <T> ResponseVO<T> success(T obj) {
        return new ResponseVO<T>(ResponseCode.SUCCESS.getCode(),"",obj);
    }
    public static <T> ResponseVO<T> failed(String msg){
        return new ResponseVO<>(ResponseCode.ERROR.getCode(), msg, null);
    }
    public static <T> ResponseVO<T> getInstance(ResponseVO resultCode, String message,T obj) {
        return new ResponseVO<T>(resultCode.getCode(), message, obj);
    }

    /**
     * 违法请求
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> ResponseVO<T> unAuthed(String msg){
        return new ResponseVO<>(ResponseCode.UNAUTHORIZATION.getCode(), msg, null);
    }
}
